unit KontoFrm;

interface

uses
  Windows, Classes, SysUtils, Variants, 
  Controls, StdCtrls, ExtCtrls, ActnList, StdActns,
  DB, DBClient, alBaseDataSet, MConnect,
  Forms, DBBaseFrm, SifrantFrm,
  PoslovanjeSrv_TLB, 
  cxClasses, cxControls, cxGraphics, cxContainer, cxStyles, cxEditRepositoryItems,
  cxCustomData, cxData, cxFilter,
  cxEdit, cxDBEdit, cxTextEdit, cxDBData,
  cxGrid, cxGridLevel, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxMaskEdit,
  cxDBEditRepository, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox, cxDataStorage, ImgList,
  BaseRpt, alActions, cxCheckBox, kdbinfo, kdbstruc;

type
  TfrmKonto = class(TfrmSifrant)
    scnRazred: TSharedConnection;
    cdsRazred: TBaseDataSet;
    dtsrcRazred: TDataSource;
    lblRazred: TLabel;
    lkpcbRazred: TcxDBLookupComboBox;
    rpstMainRazredOpisEdit: TcxEditRepositoryLookupComboBoxItem;
    grdtvMainRazredOpis: TcxGridDBBandedColumn;
    rpstMainSifra: TcxEditRepositoryMaskItem;
    lblSifra: TLabel;
    edtSifra: TcxDBMaskEdit;
    grdtvMainSifra: TcxGridDBBandedColumn;
    rpstMainRazredOpis: TcxEditRepositoryTextItem;
    actnCopy: TAction;
    actnPrintItems: TReportPrint;
    chkbxRazredObvezen: TcxDBCheckBox;
    rpstMainRazredObvezen: TcxEditRepositoryCheckBoxItem;
    grdtvMainRazredObvezen: TcxGridDBBandedColumn;
    procedure actnOpravilaExecute(Sender: TObject);
  private
    { Private declarations }
  protected
    function GetSessionParamRelations(DataSet: TDataSet): TSessionParamRelations; override;
    procedure Deinitialize; override;
    procedure DoDBRefresh; override;
    procedure Initialize; override;
    procedure SetDefaultControl; override;
  public
    procedure Copy(APoslovnoLetoID: Integer);
  end;

var
  frmKonto: TfrmKonto;

implementation

uses
  MainFrm, KontoKopiranjeFrm;

{$R *.dfm}

{ TfrmKonto }

procedure TfrmKonto.actnOpravilaExecute(Sender: TObject);
var
  Form: TfrmKontoKopiranje;
  ModalResult: Integer;
  PoslovnoLetoID: Integer;
begin
  inherited;
  if Sender = actnCopy then
  begin
    Form := TfrmKontoKopiranje.Create(nil, Session);
    try
      ModalResult := Form.ShowModal;
      if ModalResult = mrOK then
      begin
        PoslovnoLetoID := StrToInt(VarToStrDef(Form.lkpcbPoslovnoLeto.Properties.Value, '0'));
        Copy(PoslovnoLetoID);
        cdsMain.Refresh;
      end;
    finally
      Form.Free;
    end;
  end;
end;

procedure TfrmKonto.Copy(APoslovnoLetoID: Integer);
begin
  (cdsMain.AppServer as IrdmKonto).Copy(Session, APoslovnoLetoID);
end;

procedure TfrmKonto.Deinitialize;
begin
  cdsRazred.Close;
  inherited;
end;

procedure TfrmKonto.DoDBRefresh;
begin
  inherited;
  cdsRazred.Refresh;
end;

function TfrmKonto.GetSessionParamRelations(DataSet: TDataSet): TSessionParamRelations;
begin
  if DataSet = cdsMain then
  begin
    SetLength(Result, 1);
    Result[0].FieldName := 'REF_ID';
    Result[0].SessionName := 'POSLOVNO_LETO_ID';
  end;
end;

procedure TfrmKonto.Initialize;
begin
  inherited;
  cdsRazred.Open;
end;

procedure TfrmKonto.SetDefaultControl;
begin
  inherited;
  if DataSource = dtsrcMain then
    ActiveControl := edtSifra;
end;

initialization
//  RegisterClass(TrptKonto);

end.
